<?php
/**
 * Created by PhpStorm.
 * User: 68008000
 * Date: 2017/11/27
 * Time: 10:54
 */

namespace app\common\model;


use think\Model;

/**
 * Class GoodsList
 * @package app\common\model
 * 货品列表管理模板
 */
class GoodsList extends Model
{
    //连接数据库
    protected $table= 'shop_goods-list';
    protected $pk= 'glid';
    //添加
    public function add($data){
        //添加
        $data['combine'] = implode(',',$data['combine']);
        $result = $this->validate(true)->save($data);
        if (false == $result) {
            return ['valid' => 0, 'msg' => $this->getError()];
        } else {
            return ['valid' => 1, 'msg' => '添加成功！'];
        }
    }
    //编辑
    public function edid($data){
        $glid=input('param.glid');
        //编辑
        $res = $this->validate(true)->save($data,['glid' => $glid]);
        if(false === $res){
            // 验证失败 输出错误信息
            return ['valid'=>0,'msg'=>'修改失败'];
        }else{

            return ['valid'=>1,'msg'=>'修改成功'];
        }

    }
    //删除
    public function del($glid){
        $res =db('goods-list')->where('stock',0)->delete($glid);
        if ($res){
            return ['valid'=>1,'msg'=>'删除成功'];
        }else{
            return ['valid'=>0,'msg'=>'删除失败'];
        }
    }
}